package com.pccw.client.urlclient;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

import org.apache.http.cookie.Cookie;

import com.acrm.client.entity.staff.Staff;


public class ClientTest {

    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception {
    	execute() ;
    }
    
    
    public static void execute() throws Exception{
    	String s="http://localhost:8080/CRMServer/test/ctaclist.action";
    	//String s="http://www.baidu.com";
    	URL u=new URL(s);
    	URLConnection conn=u.openConnection();
    	conn.addRequestProperty("cookie", "JSESSIONID=BB673C23BBA8BD301CCB9BE3A57B2639");
    	System.out.println(conn.getDate());
    	System.out.println(conn.getContentLength());
    	System.out.println(conn.getHeaderFields());
    	System.out.println(proessSetCookie(conn));
    	/*ObjectOutputStream o=new ObjectOutputStream(conn.getOutputStream());
    	Staff staff=new Staff();
    	staff.setStaffName("guxuede");
    	o.writeObject(staff);
    	conn.getInputStream();*/
    }

    private static String proessSetCookie(URLConnection conn){
    	List<String> cookies=conn.getHeaderFields().get("Set-Cookie");
    	String session=null;
    	if(cookies!=null && cookies.size()>0 && (session=cookies.get(0))!=null){
    		return session.substring(0, session.indexOf(';'));
    	}
    	return null;
    }
}
